#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

vector<pair<int, int>> Sort(vector<int> nums)
{
	unordered_map<int, int> count;
	vector<pair<int, int>> sequence;

	for (auto num : nums)
	{
		count[num]++;
	}

	for (auto it = count.begin(); it != count.end(); it++)
	{
		// 把 数值-计数 加入到vector中，方便按计数排序
		sequence.push_back(pair<int, int>(it->first, it->second));
	}

	std::sort(sequence.begin(), sequence.end(), [=](std::pair<int, int>& a, std::pair<int, int>& b) { return (a.second > b.second) || (a.second == b.second && a.first < b.first); });

	return sequence;
}

int main()
{
	vector<int> nums;
	
	int num;
	cout << "请输入共几个数：";		// 12
	cin >> num;						// 5 2 3 3 1 3 4 2 5 2 3 5

	cout << "请输入数字：" << endl;
	while (num--)
	{
		unsigned short tmp;
		cin >> tmp;
		nums.push_back(tmp);
	}
	cout << endl;

	vector<pair<int, int>> result = Sort(nums);

	for (auto it = result.begin(); it != result.end(); it++)
	{
		cout << it->first << " " << it->second << endl;
	}

	return 0;
}
